package com.woniuxy.comsumer.controller;

import com.rabbitmq.client.Channel;
import com.woniuxy.comsumer.form.UserRegMSG;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Component
@Slf4j
public class UserRegController {

//    @RabbitListener(bindings ={@QueueBinding(value = @Queue(value = "*.*.message",durable = "true"),
//            exchange =@Exchange(value = "user.exchange",type = "topic"),key = "user.binding")})
//    public void sendMessage(UserRegMSG userRegMSG, Channel channel,
//                              @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException{
//      log.info("发送短信:{}",userRegMSG.getName());
//        channel.basicAck(deliveryTag,true);
////      return "短信ok";
//    }
//
//    @RabbitListener(bindings ={@QueueBinding(value = @Queue(value = "*.queue.*",durable = "true"),
//            exchange =@Exchange(value = "user.exchange",type = "topic"),key = "user.binding")})
//    public void sendAlone(UserRegMSG userRegMSG, Channel channel,
//                            @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException{
//        log.info("给{}：{}发私信",userRegMSG.getId(),userRegMSG.getName());
//        channel.basicAck(deliveryTag,true);
////        return "私信ok";
//    }
//
//    @RabbitListener(bindings ={@QueueBinding(value = @Queue(value = "user.#",durable = "true"),
//            exchange =@Exchange(value = "user.exchange",type = "topic"),key = "user.binding")})
//    public void clearSorce(UserRegMSG userRegMSG, Channel channel,
//                             @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException{
//        log.info("清除用户{}积分",userRegMSG.getId());
//        channel.basicAck(deliveryTag,true);
////        return "积分ok";
//    }


//    @RabbitListener(queues = "user.queue.message")
//    public void createorder(UserRegMSG userRegMSG, Channel channel,
//                           @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException{
//        log.info("进入创建订单{}",userRegMSG.getId());
////        channel.basicNack(deliveryTag,false,true);
//
//    }

    @RabbitListener(queues = "order.dead.queue")
    public void delorder(UserRegMSG userRegMSG, Channel channel,
                           @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag) throws IOException{
        log.info("进入删除订单{}",userRegMSG.getId());
        channel.basicAck(deliveryTag,true);

    }
}
